package com.health.system.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.system.domain.MallAfterSale;
import com.health.system.service.IMallAfterSaleService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 售后管理Controller
 * 
 * @author ruoyi
 * @date 2025-10-30
 */
@RestController
@RequestMapping("/system/sale")
public class MallAfterSaleController extends BaseController
{
    @Autowired
    private IMallAfterSaleService mallAfterSaleService;

    /**
     * 查询售后管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallAfterSale mallAfterSale)
    {
        startPage();
        List<MallAfterSale> list = mallAfterSaleService.selectMallAfterSaleList(mallAfterSale);
        return getDataTable(list);
    }

    /**
     * 导出售后管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sale:export')")
    @Log(title = "售后管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallAfterSale mallAfterSale)
    {
        List<MallAfterSale> list = mallAfterSaleService.selectMallAfterSaleList(mallAfterSale);
        ExcelUtil<MallAfterSale> util = new ExcelUtil<MallAfterSale>(MallAfterSale.class);
        util.exportExcel(response, list, "售后管理数据");
    }

    /**
     * 获取售后管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sale:query')")
    @GetMapping(value = "/{afterSaleId}")
    public AjaxResult getInfo(@PathVariable("afterSaleId") Long afterSaleId)
    {
        return success(mallAfterSaleService.selectMallAfterSaleByAfterSaleId(afterSaleId));
    }

    /**
     * 新增售后管理
     */
    @PreAuthorize("@ss.hasPermi('system:sale:add')")
    @Log(title = "售后管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallAfterSale mallAfterSale)
    {
        return toAjax(mallAfterSaleService.insertMallAfterSale(mallAfterSale));
    }

    /**
     * 修改售后管理
     */
    @PreAuthorize("@ss.hasPermi('system:sale:edit')")
    @Log(title = "售后管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAfterSale mallAfterSale)
    {
        return toAjax(mallAfterSaleService.updateMallAfterSale(mallAfterSale));
    }

    /**
     * 删除售后管理
     */
    @PreAuthorize("@ss.hasPermi('system:sale:remove')")
    @Log(title = "售后管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{afterSaleIds}")
    public AjaxResult remove(@PathVariable Long[] afterSaleIds)
    {
        return toAjax(mallAfterSaleService.deleteMallAfterSaleByAfterSaleIds(afterSaleIds));
    }
}
